#include "MotionPath.h"

MotionPath::MotionPath(QObject *parent) : QObject(parent)
{
    wholeLength = 0;
    blockNumber = 0;
    pathNodes.clear();
}

void MotionPath::addPathNode(BaseNode *node)
{
    pathNodes.append(node);
    currentPos += node->getEndPoint();
    // geometry
    if (currentPos.x() < geo.minX)
        geo.minX = currentPos.x();
    else if (currentPos.x() > geo.maxX)
        geo.maxX = currentPos.x();
    if (currentPos.y() < geo.minY)
        geo.minY = currentPos.y();
    else if (currentPos.y() > geo.maxY)
        geo.maxY = currentPos.y();
    // accumulation
    wholeLength += node->getLength();
    blockNumber += 1;
}

const QList<BaseNode*>& MotionPath::getMotionPath() const
{
    return pathNodes;
}

const double& MotionPath::getWholeLength() const
{
    return wholeLength;
}

const PathGeometry& MotionPath::getPathGeometry()
{
    return geo;
}

void MotionPath::reset()
{
    wholeLength = 0;
    blockNumber = 0;
    pathNodes.clear();
    currentPos = QPointF();
    geo.reset();
}
